import Vue, { getCurrentInstance } from 'vue'
import App from './App.vue'
import router from './router'
import songList from './mockdatas/songList'
import oneSongMsg from './mockdatas/oneSongMsg'
import oneSongLrc from './mockdatas/oneSongLrc'
import oneSongMv from './mockdatas/oneSongMv'
import oneSongMvx from './mockdatas/oneSongMvx'
import comments from './mockdatas/comments'

Vue.config.productionTip = false

//ElementUI 导入
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI)

//axios的配置
import axios from 'axios'
axios.defaults.timeout = 3000
axios.defaults.baseURL = 'http://localhost:3000'

Vue.prototype.$axios = axios
//处理响应错误
axios.interceptors.response.use(function(res){
  // res为axios对象
  return res;
},function(err){
  // 接口无法使用时 使用本地保存的数据
  console.log(err.request.responseURL)
  if(err.request.responseURL.indexOf('/search?keywords=')>0){
    return songList 
  }
  if(err.request.responseURL.indexOf('/song/detail?id=')>0){
    return oneSongMsg
  }
  if(err.request.responseURL.indexOf('/lyric?id=')>0){
    return oneSongLrc
  }
  if(err.request.responseURL.indexOf('/mv/url?mvid=')>0){
    return oneSongMv
  }
  if(err.request.responseURL.indexOf('/mv/detail?mvid=')>0){
    return oneSongMvx
  }
  if(err.request.responseURL.indexOf('/comment/hot?id=')>0){
    return comments
  }
  // if(err.request.responseURL.indexOf())
});

Vue.prototype.$eventBus = new Vue()

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
